package com.guanghua.brick.html.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guanghua.brick.html.IComponent;

public class HtmlTag extends BodyTagSupport {
	
	private static Log logger = LogFactory.getLog(HtmlTag.class);
	
	public int doEndTag() throws JspException {
		//找到父亲，并add html
		Tag tag = this.getParent();
		if (tag instanceof IComponent && bodyContent != null) {
			String html = bodyContent.getString();
			if (html != null) {
				IComponent t = (IComponent)tag;
				if (t.getHtml() == null || t.getHtml().length() == 0)
					t.setHtml(html.trim());
				else
					t.setHtml(t.getHtml() + " " + html);
			}
		} else {
			logger.warn("html parent must be Icontrol and must be have body content");
		}
		return BodyTagSupport.EVAL_PAGE;
	}
}
